﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MidApp
{
    public class ManageIsStockDetail
    {
        /// <summary>
        ///Metoda pridani detail uzivateli v tymu. 
        ///</summary>
        public static void AssignDetailToUserAndTeam(int UserID, int TeamID, int DetailID)
        {
            var db = MidApp.LinqUse.DBConn;

            AppLib.IsStockDetail stockDetail = new AppLib.IsStockDetail();

            stockDetail.TeamID = TeamID;
            stockDetail.UserID = UserID;
            stockDetail.DetailID = DetailID;

            db.IsStockDetails.InsertOnSubmit(stockDetail);
            db.SubmitChanges();

        }
        /// <summary>
        ///Metoda vraci seznam vsech detailu uzivatele v tymu.
        ///</summary>
        public static List<AppLib.IsStockDetail> GetAllUserDetails(int UserID, int TeamID)
        {
            var db = MidApp.LinqUse.DBConn;

            return (from IsStockDetail in db.IsStockDetails where IsStockDetail.UserID == UserID && IsStockDetail.TeamID == TeamID select IsStockDetail).ToList();
        }
        /// <summary>
        ///Metoda smaze detail uzivatele v konkretnim tymu.
        ///</summary>
        public static void DeleteDetail(int detailID, int teamID, int userID)
        {
            var db = MidApp.LinqUse.DBConn;

            AppLib.IsStockDetail detail = (from IsStockDetail in db.IsStockDetails where IsStockDetail.UserID == userID && IsStockDetail.TeamID == teamID && IsStockDetail.DetailID == detailID select IsStockDetail).First();
            db.IsStockDetails.DeleteOnSubmit(detail);
            db.SubmitChanges();

        }
        /// <summary>
        ///Metoda smaze vsechny detaily uzivatele v konkretnim tymu.
        ///</summary>
        public static void DeleteDetails(int teamID, int userID)
        {
            var db = MidApp.LinqUse.DBConn;

            var detail = (from IsStockDetail in db.IsStockDetails where IsStockDetail.UserID == userID && IsStockDetail.TeamID == teamID select IsStockDetail).ToList();
            
            foreach (var item in detail)
            {
                db.IsStockDetails.DeleteOnSubmit(item);
                db.SubmitChanges();
            }


        }
    }
}
